import java.util.*;

public class PrimeNumberMethod {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Kādā mērogā meklēt pirmskaitļus? ");
        int skaits = scanner.nextInt();
        System.out.println("\nPirmskaitļi no pirmajiem 50 ir ");
        announcePrimes(skaits);
        
    }
    
    public static void announcePrimes(int n) {
        final int NUMBER_OF_PRIMES_PER_LINE = 10;
        int count = 0;
        int num = 2;
        
        while(count < n) {
            
            if(isPrime(num)) {
                count++;
                
                if(count % NUMBER_OF_PRIMES_PER_LINE == 0) {
                    System.out.printf("%-5s\n", num);
                }
                else
                    System.out.printf("%-5s", num);
            }
            num++;
        }
    }
    
    public static boolean isPrime(int number) {
        
        for(int divisor = 2; divisor <= number; divisor++) {
            if(number % divisor == 0) {
                return false;
            }
        }
        
        return true;
    }
}